package com.kaifamiao.repositories;

import com.kaifamiao.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class BaseRepositoryImpl implements BaseRepository<User> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JdbcTemplate template;

    @Override
    public int update(User user) {
        logger.info("更新用户");
        String sql = "UPDATE t_users " +
                     "SET account=?, email=?, tel=?, nickname=?, gender=?, birthdate=?, married=?, admin=? " +
                     "WHERE id = ?";
        Object[] params = {
                user.getAccount(),
                user.getEmail(),
                user.getTel(),
                user.getNickname(),
                user.getGender().name(),
                java.sql.Date.valueOf(user.getBirthdate()),
                user.isMarried(),
                user.isAdmin(),
                user.getId()
        };
        return template.update(sql, params);
    }

}
